<script>
export default {
  data() {
    return {
      ruleFrom: {
        userAccount: '',
        userPassword: '',
      },
      password_ok: '',
    }
  },
  methods: {
    clickFrom(res) {
      if(res.userAccount.length < 1) {
        this.$message.error("用户名不能为空")
      }else if (res.userPassword.length < 6 || res.userPassword.length > 14){
        this.$message.error("密码长度为6-14个字符")
      }else if (res.userPassword !== this.password_ok){
        this.$message.error("两次密码不一致")
      }else {
        this.register();
      }
    },
    async register() {
      const {data : res} = await this.$http.post('/flower-manage/register',this.ruleFrom);
      console.log(res);
      if(res.code === 1) {
        this.$message.success(res.data)
        this.$router.push("/")
      }else {
        this.$message.error(res.msg)
      }
    }
  }
}
</script>
<template>
  <div class="app">
    <section>
      <div class="body">
        <h1>用户注册</h1>
          <label for="account">账号：</label
          ><input
            type="text"
            name="account"
            v-model="ruleFrom.userAccount"
            class="name"
            autocomplete="off"
          /><br />
          <label for="password">密码：</label
          ><input
            type="password"
            name="password"
            v-model="ruleFrom.userPassword"
            autocomplete="off"
          /><br />
          <label for="password_ok" class="ok">确认密码：</label
          ><input
            type="password"
            name="password_ok"
            v-model="password_ok"
            class="pass"
            autocomplete="off"
          />
          <button @click="clickFrom(ruleFrom)">注册</button>
          <a href="/" class="login_a">登录</a>
      </div>
    </section>
  </div>
</template>
<style lang="less" scoped>
* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}
label {
  font-size: 25px;
}
a {
  color: #000;
  text-decoration: none;
}
input {
  outline: none;
  border: 0;
  height: 45px;
  width: 300px;
  margin-bottom: 50px;
  border-radius: 10px;
  font-size: 25px;
  padding-left: 10px;
  background: rgba(255, 255, 255, 0.5);
}
.app {
  position: fixed;
  width: 100%;
  height: 100%;
  background: url(./image/register.jpg) no-repeat;
  background-size: 100% 100%;
  section {
    position: relative;
    .body {
      position: absolute;
      height: 500px;
      width: 500px;
      right: 450px;
      top: 330px;
      padding-top: 50px;
      h1 {
        font-size: 42px;
        font-family: serif;
        font-weight: 400;
        margin-bottom: 25px;
        color: orange;
      }
      .ok {
        float: left;
        margin-left: 14px;
      }
      .pass {
        float: left;
      }
      button {
        .button_a();
        left: 110px;
      }
      .login_a {
        .button_a();
        left: 260px;
        text-align: center;
        line-height: 50px;
      }
    }
  }
}
.button_a {
  position: absolute;
  bottom: 60px;

  font-size: 20px;
  height: 50px;
  width: 100px;
  border: 0;
  background-color: orange;
  border-radius: 10px;
}
</style>
